package com.wangzhixuan.apiController;





import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wangzhixuan.commons.base.ApiBaseController;
import com.wangzhixuan.commons.constant.ApiCode;
import com.wangzhixuan.mapper.BaseInfoMapper;
import com.wangzhixuan.model.BaseInfo;
import com.wangzhixuan.model.Version;
import com.wangzhixuan.model.vo.ExcelJobInfomationVo;
import com.wangzhixuan.model.wordVo.WordAnalysisVo;
import com.wangzhixuan.model.wordVo.WordMeetingVo;
import com.wangzhixuan.model.wordVo.WordPeopleVo;
import com.wangzhixuan.model.wordVo.WordSurveyVo;
import com.wangzhixuan.service.IVersionService;


/**
 * @description：
 * @author：zhixuan.wang
 * @date：2015/10/1 14:51
 */
//@CrossOrigin(origins = "*")当前版本1.7 会报错，原因版本太低 http://spring.io/guides/gs/rest-service-cors/
@Controller
@RequestMapping("/api")
public class BriefingApiController extends ApiBaseController{

	
	@Autowired
	private IVersionService versionService;
	
	@Autowired
    private BaseInfoMapper baseInfoMapper;
	
	
	
	
	@RequestMapping("/html")
    @ResponseBody
    public String html(Integer workId) {
		return getRootPath()+"api/web?workId="+workId;
	}
	
	
	@RequestMapping("/web")
    @ResponseBody
    public ModelAndView wordWeb(Integer workId) {
		ModelAndView mv = new ModelAndView();
		ExcelJobInfomationVo excelJobInfo = baseInfoMapper.selectExJobInfo(workId);
		WordSurveyVo wdSurvey = baseInfoMapper.selectWdSurvey(workId);
		WordMeetingVo wordMeetingVo = baseInfoMapper.selectWdMeeting(workId);
		List<WordAnalysisVo> wordAnalysisVo = baseInfoMapper.selectWdAnalysis(workId);
		List<String> wdPhenom = baseInfoMapper.selectWdPhenom(workId);
		List<WordPeopleVo> wordPeopleVo = baseInfoMapper.selectWdPeople(workId);
		List<String> imgPath = baseInfoMapper.selectImgPath(workId);
		BaseInfo baseInfo = baseInfoMapper.selectById(workId);
		String wordUrl = baseInfo.getWordUrl();
		mv.addObject("A", excelJobInfo.getJobName()==null?"":excelJobInfo.getJobName());
		SimpleDateFormat DatetoString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        mv.addObject("A", excelJobInfo.getJobName()==null?"":excelJobInfo.getJobName());
        mv.addObject("B", excelJobInfo.getJobDescribe()==null?"":excelJobInfo.getJobDescribe());
        mv.addObject("C", excelJobInfo.getJobCategory()==null?"":excelJobInfo.getJobCategory());
        mv.addObject("D", excelJobInfo.getAddress()==null?"":excelJobInfo.getAddress());
        mv.addObject("E", excelJobInfo.getStatus()==null?"":excelJobInfo.getStatus());
        mv.addObject("F", excelJobInfo.getCreatName()==null?"":excelJobInfo.getCreatName());
        String G = DatetoString.format(excelJobInfo==null?new Date():excelJobInfo.getEndTime());
        mv.addObject("G", G);
        //mv.addObject("H", excelJobInfo.getCreatPhone());
        String I = DatetoString.format(excelJobInfo==null?new Date():excelJobInfo.getInfaceEndTime());
        mv.addObject("I", I);
        String J = DatetoString.format(excelJobInfo==null?new Date():excelJobInfo.getStartTime());
        String K = DatetoString.format(excelJobInfo==null?new Date():excelJobInfo.getEndTime());
        mv.addObject("J", J);
        mv.addObject("K", K);
        System.out.println(wdSurvey);
        if(wdSurvey==null){
	        mv.addObject("L", "");
	        mv.addObject("M", "");
	        mv.addObject("N", "");
	        mv.addObject("O", "");
	        mv.addObject("P", "");
        }
        else{
	        mv.addObject("L", wdSurvey.getSurveyName()==null?"":wdSurvey.getSurveyName());
	        mv.addObject("M", wdSurvey.getSurveyContent()==null?"":wdSurvey.getSurveyContent());
	        mv.addObject("N", wdSurvey.getBlackoutRange()==null?"":wdSurvey.getBlackoutRange());
	        mv.addObject("O", wdSurvey.getSecurity()==null?"":wdSurvey.getSecurity());
	        mv.addObject("P", wdSurvey.getUserName()==null?"":wdSurvey.getUserName());
        }

        if(wordMeetingVo==null){
 		mv.addObject("Q", "未开始");
 		mv.addObject("R", "未开始");
        }
        else{
        	if("11".equals(wordMeetingVo.getType())){
	        	if("22".equals(wordMeetingVo.getStatus())){
	        		mv.addObject("Q", "未结束");
	        		mv.addObject("R", "未开始");
	        	}
	        	if("23".equals(wordMeetingVo.getStatus())){
	        		mv.addObject("Q", "已结束");
	        		mv.addObject("R", "已结束");
	        	}
	        	
	        }else if("12".equals(wordMeetingVo.getType())){
	        	if("22".equals(wordMeetingVo.getStatus())){
	        		mv.addObject("Q", "已结束");
	        		mv.addObject("R", "未结束");
	        	}
	        	if("23".equals(wordMeetingVo.getStatus())){
	        		mv.addObject("Q", "已结束");
	        		mv.addObject("R", "已结束");
	        	}
	        }else{
     		mv.addObject("Q", "已结束");
     		mv.addObject("R", "已结束");
	        }
        }
        mv.addObject("wordUrl", wordUrl);
        mv.addObject("wdPhenom",wdPhenom);
        mv.addObject("wordAnalysisVo",wordAnalysisVo);
        mv.addObject("wordPeopleVo",wordPeopleVo);
        mv.addObject("imgPath",imgPath);
        mv.setViewName("word");
        return mv;
    }
	
}
